package com.yinxin.wudasuanfa.sort;

import java.util.Arrays;

/**
 * @author yinxin
 * @version 1.0
 * @Description: 冒泡排序
 * @date 2022/4/1919:27
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = new int[]{1,2,5,8,9,13,89,21,11};
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i; j < arr.length - 1 - i; j++) {
                if (arr[j + 1] < arr[j]) {
                    myswap(arr, j+1, j);
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }

    //交换数组中两个元素的顺序
    private static void myswap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}
